package com.shangjinrong.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shangjinrong.domain.vo.BorrowInfoApprovalVO;
import com.shangjinrong.domain.vo.BorrowInfoDetailVO;
import com.shangjinrong.result.R;
import com.shangjinrong.service.BorrowInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("admin/borrowInfo")
@Slf4j
public class AdminBorrowInfoController {

    @Autowired
    private BorrowInfoService borrowInfoService;

    @GetMapping("paging/{current}/{size}")
    public R paging(@PathVariable long current, @PathVariable long size) {
        Page<BorrowInfoDetailVO> page = new Page<>(current, size);
        borrowInfoService.paging(page);
        return R.ok().data("paging", page);
    }

    @GetMapping("detail/{id}")
    public R detail(@PathVariable Long id) {
        BorrowInfoDetailVO borrowInfoDetail = borrowInfoService.getBorrowInfoDetail(id);
        return R.ok().data("borrowInfoDetail", borrowInfoDetail);
    }

    @PostMapping("approval")
    public R approval(@RequestBody BorrowInfoApprovalVO borrowInfoApprovalVO){
        borrowInfoService.approval(borrowInfoApprovalVO);
        return R.ok().message("审批完成");
    }

}
